// 通用的时间绑定函数
function bindEvent(elm, type, fn) {
  elm.addEventListener(type, fn);
}

const btn1 = document.getElementById("btn1");

// 绑定btn1的时间
bindEvent(btn1, "click", function (e) {
  e.preventDefault(); // 阻止默认行为 比如复选框的选中,但是还是会冒泡
  console.log("点击l");
});

const body = document.body;

bindEvent(body, "click", (event) => {
  console.log("body clicked");
  console.log("body event", event.target);
});



// ! 事件冒泡 触发div的 然后再冒泡到外面body
const div2 = document.getElementById("div2");
bindEvent(div2, "click", (event) => {
  event.stopPropagation();// ?阻止冒泡 不会冒泡到body
  
  console.log("div2 clicked");
  console.log("div2 event", event.target);
});
